<?php

    // +----------------------------------------------------------------------
    // | 记事本插件
    // +----------------------------------------------------------------------
    // | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
    // +----------------------------------------------------------------------
    // | Author: 微尘 <yicmf@qq.com>
    // +----------------------------------------------------------------------

    namespace addon\note;


    use app\event\ucenter\User;
	use think\Event;
	use yicmf\addon\controller\Controller;
	use addon\note\model\Note as NoteModel;

    class Note extends Controller
    {
        /**
         * 当前插件需要的钩子.
         */
        protected $hook_list = [
            'admin_head',
        ];

        public function install()
        {
            return true;
        }

        public function uninstall()
        {
            return true;
        }
		public function subscribe(Event $event)
		{
			$event->listen('admin_head', [$this,'adminHead']);
		}
        /**
         * 实现的admin_head钩子方法.
         *
         * @author 微尘 <yicmf@qq.com>
         */
        public function adminHead($param)
        {
            $config = $this->getConfig();
            $this->assign('addon_config', $config); 
            $user = request()->user;
            $note = NoteModel::where('module', request()->auth_module)->where('user_id', $user['id'])->find();
            if ($note) {
                $this->assign('addon_site_note', $note);
            }
			$this->assign('module', request()->auth_module);
            return $this->fetch('info');
        }
    }
